// +---------------------------------------------------------------------------+
// | Copyright (c) 2014-2015.                                                  |
// | Website: http://www.mamahaocai.com/                                       |
// | Author : David 黎 <lovedavid2046@163.com>                                 |
// +---------------------------------------------------------------------------+
/**
 * 手机号合法验证
 */
function get_mobile_phone(){
    //var email=document.getElementById('username').value;
    //var reg=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    var mobile=document.getElementById('phone').value;
    var reg=/^(13[0-9]|15[0|1|2|3|6|7|8|9]|18[0|2|3|5|6|7|8|9]|17[0])\d{8}$/;
    var result=document.getElementById("result");
    var messages=document.getElementById("messages");
    var res=mobile.match(reg);
    if(res){
        $.post("<?php echo U('/phoneCheck');?>",{phone:mobile},function (msg){
            if(msg=="0"){
                document.getElementById('errorImg').src="__PUBLIC__/images/tick.png";
                messages.innerHTML="手机号可用";
                result.style.display="block";
                $(" #result").fadeOut(2000);
            }else if(msg=="1"){
                document.getElementById('errorImg').src="__PUBLIC__/images/error.jpg";
                messages.innerHTML="该手机号已被注册";
                result.style.display="block";
                document.getElementById('phone').value="";
                document.getElementById('phone').focus();
            }else{
                alert(msg);
            }
        });
    }else{
        document.getElementById('errorImg').src="__PUBLIC__/images/error.jpg";
        messages.innerHTML="请填写正确的手机号格式";
        result.style.display="block";
        document.getElementById('phone').focus();
    }
}

/**
 * 密码一致验证
 */
function checkPass(){
    var pwd=document.getElementById('password').value;
    var conPwd=document.getElementById('conPassword').value;
    var reg=/^[\@A-Za-z0-9\!\#\$\%\^\&\*\.\~]{6,18}$/;
    var result=document.getElementById("result");
    var messages=document.getElementById("messages");
    var res=pwd.match(reg);
    if(res){
        if(pwd!=conPwd){
            document.getElementById('errorImg').src="__PUBLIC__/images/error.png";
            messages.innerHTML="两次输入密码不一致";
            result.style.display="block";
            document.getElementById('conPassword').focus();
        }else{
            if(result.style.display!="none"){
                result.style.display="none";
            }
        }
    }else{
        document.getElementById('errorImg').src="__PUBLIC__/images/error.jpg";
        messages.innerHTML="密码长度不合法";
        result.style.display="block";
        document.getElementById('password').focus();
    }
}

/**
 * 注册验证
 */
function mndregCheck(){
    //var email=document.getElementById('username').value;
    //var reg=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    var mobile=document.getElementById('phone').value;
    var password=document.getElementById('password').value;
    var conPassword=document.getElementById('conPassword').value;
    var verify=document.getElementById('verify').value;
    var reg=/^(13[0-9]|15[0|1|2|3|6|7|8|9]|18[0|2|3|5|6|7|8|9]|17[0])\d{8}$/;
    var result=document.getElementById("result");
    var messages=document.getElementById("messages");
    var res=mobile.match(reg);
    if(res){
        $.post("<?php echo U('/mndregCheck');?>",{mobile:mobile,password:password,conPassword:conPassword,verify:verify},function(msg){
            if(msg=="0"){
                result.style.display="none";
                if(result.style.display=="none"){
                    window.location.href="<?php echo U('/tips');?>";
                }else{
                    document.getElementById('errorImg').src="__PUBLIC__/images/error.jpg";
                    messages.innerHTML="错误信息未处理完成。";
                    result.style.display="block";
                }
            }else if(msg=="1"){
                document.getElementById('errorImg').src="__PUBLIC__/images/error.jpg";
                messages.innerHTML="数据写入失败。";
                result.style.display="block";
            }else if(msg=="2"){
                document.getElementById('errorImg').src="__PUBLIC__/images/error.png";
                messages.innerHTML="两次输入密码不一致。";
                result.style.display="block";
                document.getElementById('conPassword').focus();
            }else if(msg=="3"){
                document.getElementById('errorImg').src="__PUBLIC__/images/error.png";
                messages.innerHTML="验证码错误。";
                result.style.display="block";
                document.getElementById('verify').focus();
            }else if(msg=="4"){
                document.getElementById('errorImg').src="__PUBLIC__/images/error.jpg";
                messages.innerHTML="该手机号已经被注册。";
                result.style.display="block";
                document.getElementById('phone').focus();
            }else if(msg=="5"){
                document.getElementById('errorImg').src="__PUBLIC__/images/error.jpg";
                messages.innerHTML="请填写正确的手机号格式。";
                result.style.display="block";
                document.getElementById('phone').focus();
            }else if(msg=="6"){
                alert("您好！请先注册。");
                window.location.href="<?php echo U('/mstreg');?>";
            }else if(msg=="7"){
                alert("对不起！验证码已过期。");
                window.location.href="<?php echo U('/mstreg');?>";
            }else if(msg=="8"){
                document.getElementById('errorImg').src="__PUBLIC__/images/error.jpg";
                messages.innerHTML="密码长度不合法。";
                result.style.display="block";
                document.getElementById('password').focus();
            }else{
                alert(msg);
            }
        });
    }else{
        document.getElementById('errorImg').src="__PUBLIC__/images/error.jpg";
        messages.innerHTML="请填写正确的手机号格式";
        result.style.display="block";
        document.getElementById('phone').focus();
    }
}

